package com.dream.dao.base;

/**
 * 
 * @author Evan
 * @date 2013-8-25
 * 
 */
import java.util.List;

import org.springframework.stereotype.Repository;

import com.dream.model.app.AppUserResource;
import com.dream.utils.hibernate.DetachedCriteriaBuilder;
import com.dream.utils.hibernate.DreamBaseDAO;

@Repository
public class AppUserResourceDAO extends DreamBaseDAO<AppUserResource> {
	
	/**
	 * 
	 * @author evan
	 * @Revision
	 * @date 2013-9-9
	 * @param userId
	 * @return
	 */
	public List<AppUserResource> getByUser(final String userId){
		
		DetachedCriteriaBuilder builder = DetachedCriteriaBuilder.instance(AppUserResource.class);
		builder.innerJoin("appResource", "ar").addEq("ar.deleted", false);
		builder.addEq("id.userId", userId).addEq("deleted", false);
		
		return select(builder);
		
	}
	
	/**
	 * 
	 * @author evan
	 * @Revision
	 * @date 2013-9-9
	 * @param userId
	 * @return
	 */
	public Integer deleteByUser(final String userId){
		
		final String DEL_BY_USER = "delete AppUserResource where user_id=?";
		return bulkUpdate(DEL_BY_USER, userId);
	}
}
